// pages/register2/register2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:'',
    realName:'',
    userName:'',
    organizeName:'',
    organizeId:'',
    phone:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const organizeCode = wx.getStorageSync('organizeCode')
    const organizeName = wx.getStorageSync('organizeName')
    this.setData({
      phone:options.phone,
      organizeId : organizeCode,
      organizeName
    })
  },
  onShow: function () {
    const organizeCode = wx.getStorageSync('organizeCode')
    const organizeName = wx.getStorageSync('organizeName')
    this.setData({
      organizeId : organizeCode,
      organizeName
    })
  },
  /**
   * 返回
   */
  handlerGobackClick(){
    wx.navigateBack()
  },
  /**
   * 下一步
   */
  nextStep(){
    const realName = this.data.realName
    const userName = this.data.userName
    const organizeId = this.data.organizeId
    const phone = this.data.phone
    if(organizeId==''){
      this._show_error('请输入组织机构！')
      return
    }
    if(userName==''){
      this._show_error('请输入用户名！')
      return
    }
    if(realName==''){
      this._show_error('请输入姓名！')
      return
    }
    wx.navigateTo({
      url: `/pages/register3/register3?realName=${realName}&userName=${userName}&organizeId=${organizeId}&phone=${phone}`
    })
  },
  /**
   * 组织机构
   */
  goToOrganize(){
    wx.navigateTo({
      url:'/pages/organize/organize?type=register'
    })
  },
  _show_error(msg) {
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 2000
    })
  },
  /**
   * input 数据绑定
   */
  updateValue(e) {
    let name = e.currentTarget.dataset.name;
    let nameMap = {}
    nameMap[name] = e.detail
    this.setData(nameMap)
  },
})
